﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace flattiverseGameClient.Helper
{
    internal static class VectorMagicHelper
    {
        /// <summary>
        /// Calculates the Distance between me and an given Object
        /// </summary>
        /// <param name="v_objPosition">Object Position</param>
        /// <param name="objRadius">Object Radius</param>
        /// <param name="shipRadius">my Ships radius</param>
        /// <returns>the real distance to an object</returns>
        internal static float calcDistance(Flattiverse.Vector v_objPosition, float objRadius, float shipRadius)
        {
            float resturnDistance = 0;

            resturnDistance = v_objPosition.Length - objRadius - shipRadius;

            return resturnDistance;
        }

        /// <summary>
        /// Calculate a units movement.
        /// </summary>
        /// <param name="oldPosVector">old known Position Vector</param>
        /// <param name="unitMoveVector">old known movement Vector</param>
        /// <param name="ShipMovement">my ships movement</param>
        /// <param name="fixedUnit">Is unit fixed or not</param>
        /// <returns>Vector of calculated Position</returns>
        internal static Flattiverse.Vector calcUnitMovement(Flattiverse.Vector oldPosVector, Flattiverse.Vector unitMoveVector, Flattiverse.Vector ShipMovement, bool fixedUnit)
        {
            Flattiverse.Vector calcedUnitMovement = new Flattiverse.Vector(0.0f, 0.0f);
            if (fixedUnit)
            {
                //Fixed Units
                calcedUnitMovement = oldPosVector - ShipMovement;
            }
            else
            {
                //non Fixed Units
                calcedUnitMovement = oldPosVector + unitMoveVector;
            }

            return calcedUnitMovement;
        }


        internal static Flattiverse.Vector rotatVectorBy180(Flattiverse.Vector vector)
        {
            float angle = vector.Angle;

            if (vector.Angle == 180)
                angle = vector.Angle = 0;
            else if (vector.Angle == 0)
                angle = vector.Angle = 180;
            else if (vector.Angle > 180)
                angle = vector.Angle - 180;
            else
                angle = vector.Angle + 180;

            return new Flattiverse.Vector(angle, vector.Length);
        }
    }
}
